package NWish.properties.object3ds
{
	import NWish.json.OrderDict;
	import NWish.properties.Properties;
	
	import away3d.containers.Scene3D;
	import away3d.primitives.WireframeCube;

	public class EmptyContainerProperties extends Properties
	{
		public function EmptyContainerProperties(app)
		{
			//
			super(app);
			
			addPropertieKeys('ContainerProperties',['name']);
		}
		
		
		override public function newType(scene,dict)
		{
			if(scene == null && dict == null)
				return new type(null);
			else if(scene)
				return new type(_app);
			else
				throw new Error();
		}
		
		
		//
		override public function propertiesToDict(obj,dict:OrderDict,read_only = false,saving = false)
		{
			super.propertiesToDict(obj,dict,read_only,saving);
			
			if(read_only == false)
			{
				if(saving)
				{
				}
				else
				{
					var num = obj.numChildren;
					var children:Array = [];
					for(var i = 0; i < num; ++i)
					{
						var  c = obj.getChildAt(i);
						if(c is WireframeCube)
							continue;
						
						children.push(c.name);
					}
					dict.push(readMark + 'children', children);
				}
			}
		}
		
		
		override public function dictToProperties(dict,obj,scene:Scene3D,isloading)
		{
			super.dictToProperties(dict,obj,scene,isloading);
			
			if(obj.parent)
				return;
			
			if(obj.parent == null)
			{
				scene.addChild(obj);
				return;
			}
			
			throw new Error();
		}
	}
}